<template>
  <div class="student">
    <h2>姓名：{{ name }}</h2>
    <h2>年龄：{{ age }}</h2>
    <h2>性别：{{ gender }}</h2>
    <div>
      <button @click="sendStudentName">把学生名发送给School组件</button>
    </div>
  </div>
</template>

<script>
import PubSub from "pubsub-js";

export default {
  data() {
    return {
      name: "张三",
      age: 12,
      gender: "男",
    };
  },
  methods: {
    sendStudentName() {
      PubSub.publish("get-student-name", this.name);
    },
  },
};
</script>

<!-- yarn add -D sass -->
<style scoped lang="scss">
.student {
  background: skyblue;
  margin: 3rem 0 3rem 0;
  padding: 1rem;
}
</style>
